package guoanmaker.operator.business.repository;

import guoanmaker.operator.business.model.ProvideServerClass;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.ArrayList;
import java.util.List;

/**
 * @author vladimir.stankovic
 *         <p>
 *         Aug 16, 2016
 */
public interface ProvideServerClassRepository extends JpaRepository<ProvideServerClass, String>, JpaSpecificationExecutor<ProvideServerClass> {
    //	@Query("select u from ProvideUser u left join fetch u.roles r where u.username=:username")
//    public Optional<ProvideServerClass> findByUsername(@Param("username") String username);
    @Query("select t from ProvideServerClass t where t.serverLevel = :serverLevel")
    Page<ProvideServerClass> findAllByServerLevel(Pageable pageable, @Param("serverLevel") Integer serverLevel);

    @Query("select t from  ProvideServerClass t where t.parentServerId = :parentServerId")
    ArrayList<ProvideServerClass> findAllByParentServerId(@Param("parentServerId") String parentServerId);
    
    @Query("select t from  ProvideServerClass t  where t.serverLevel = 1")
    List<ProvideServerClass>   selectByOneServerclass();
    @Query("select t from  ProvideServerClass t  where t.serverLevel = 2")
    List<ProvideServerClass>   selectByTwoServerclass();
}
